﻿namespace Netbits.Common.Conditions
{
	/// <summary>
	/// Validator class hold information of validating.
	/// </summary>
	/// <typeparam name="T">Type of the value to validate</typeparam>
	public class Validator<T>
	{
		#region Private Variables

		internal readonly T __Value;
		internal readonly string __Name;

		#endregion

		#region Constructor

		/// <summary>
		/// Create new validator class with the given Value and Name
		/// </summary>
		/// <param name="Name_">The argument-name of the value</param>
		/// <param name="Value_">The value to validate</param>
		public Validator( T Value_, string Name_ )
		{
			this.__Name = Name_;
			this.__Value = Value_;
		}

		#endregion

		#region Internal Functions

		/// <summary>
		/// Returns the argument name
		/// </summary>
		/// <returns>string-value of the argument-name</returns>
		internal string GetArgumentName()
		{
			if( string.IsNullOrEmpty( __Name ) )
			{
				if( __Value == null )
					return string.Empty;

				return __Value.GetType().FullName;
			}

			return __Name;
		}

		/// <summary>
		/// Returns the string value of the value.
		/// </summary>
		/// <returns>string-value of value</returns>
		internal string GetStringOfValue()
		{
			if( __Value == null )
				return "NULL";

			if( __Value is string || __Value is char )
				return string.Format( "\"{0}\"", __Value );

			return __Value.ToString();
		}

		#endregion
	}
}
